//
//  Button_5_ViewController.m
//  Tee-Study
//
//  Created by DJtd on 16/10/10.
//  Copyright © 2016年 杨迎龙. All rights reserved.
//

#import "Button_5_ViewController.h"

@interface Button_5_ViewController ()<QRCodeReaderDelegate>

@end

@implementation Button_5_ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    
    if ([QRCodeReader supportsMetadataObjectTypes:@[AVMetadataObjectTypeQRCode]]) {
        static QRCodeReaderViewController *reader = nil;
        static dispatch_once_t onceToken;
        
        dispatch_once(&onceToken, ^{
            reader = [QRCodeReaderViewController new];
        });
        reader.delegate = self;
        
        [reader setCompletionWithBlock:^(NSString *resultAsString) {
            NSLog(@"Completion with result: %@", resultAsString);
        }];
        
        [self presentViewController:reader animated:YES completion:NULL];
    }
    else {
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"当前设备无法支持该功能" preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            [self.navigationController popViewControllerAnimated:YES];
        }];
        [alertController addAction:cancelAction];
        [self presentViewController:alertController animated:YES completion:^{
        }];
    }



}


#pragma mark - QRCodeReader Delegate Methods
- (void)reader:(QRCodeReaderViewController *)reader didScanResult:(NSString *)result
{
    [self dismissViewControllerAnimated:YES completion:^{
        
        //判断是否已经扫描过
        if (result) {
            
//            self.resultReader = result;
//            [self requestTagNo:result];
            
        }
        
    }];
    
}
- (void)readerDidCancel:(QRCodeReaderViewController *)reader
{
    [self dismissViewControllerAnimated:YES completion:NULL];
}







- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
@end
